package com.example.json_parse.real_buses_info;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.internal.LinkedTreeMap;

public class RealBusInfo {	
	public static Map<String, Map<String, Object>> parseRealBusInfo(String data){
		
		Map<String,Object> map_result = new HashMap<String, Object>();  
	    Gson gson = new Gson();
	    JsonParser parser = new JsonParser();
	    JsonElement el = parser.parse(data);
	    JsonObject jsonObj = null;
	    if(el.isJsonObject()){
	        jsonObj = el.getAsJsonObject();
	    }
	    
	    String lineBusInfo = jsonObj.get("lineBusInfo").toString();
	    
	    
	    JsonElement el1 = parser.parse(lineBusInfo);
	    JsonObject jsonObj1 = null;
	    if(el1.isJsonObject()){
	        jsonObj1 = el1.getAsJsonObject();
	    }
	    
	    
	    String lineId = jsonObj1.get("lineId").toString();
	    String up_down = jsonObj1.get("up_down").toString();
		String buses = jsonObj1.get("buses").toString();
	    
		map_result.put("lineId", lineId);
		map_result.put("up_down", up_down);
		
		
		 JsonElement e2 = parser.parse(buses);
		 JsonObject jsonObj2 = null;
		 if(e2.isJsonObject()){
			 jsonObj2 = e2.getAsJsonObject();
		 }
		
		 
		
	    Map<String, Object> map = gson.fromJson(buses, HashMap.class);  

	    Map<String,  Map<String, Object>> map_buses = new HashMap<String,  Map<String, Object>>();
	    
	    
	    
	    for (String key : map.keySet())
	    {     
	    	 Map<String, Object> map1 = gson.fromJson(jsonObj2.get(key), HashMap.class);  
	    	 map_buses.put(key, map1);
	  	    
	    }
		
	    map_result.put("buses", map_buses);
	    //System.out.println(map_buses.get("2067").get("busState"));
	    return  map_buses;
	}
	
}
